package com.feemanage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.common.annotation.Anonymous;
import com.common.core.domain.R;
import com.common.core.page.PageDomain;
import com.common.core.page.TableDataInfo;
import com.common.validate.add;
import com.common.validate.edit;
import com.feemanage.domain.BizFeeAlarmSet;
import com.feemanage.domain.BizSystemRemind;
import com.feemanage.service.IBizSystemRemindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.Arrays;

/**
 * 预警信息
 */
@Api(tags="预警信息")
@RestController
@RequestMapping("/feemanage/remind")
public class BizSystemRemindController {

    @Autowired
    private IBizSystemRemindService baseService;

    /**
     * 查询列表
     * @param pageDomain
     * @param remind
     * @return
     */
    @ApiOperation("查询列表")
    @GetMapping("/list")
    public TableDataInfo list(PageDomain pageDomain, BizSystemRemind remind){
        IPage<BizSystemRemind> page = baseService.selectList(pageDomain,remind);
        return TableDataInfo.build(page.getRecords(),page.getTotal());
    }

    /**
     * 预警列表
     * @param pageDomain
     * @param set
     * @return
     */
    @ApiOperation("查询预警设置列表")
    @GetMapping("/alarmsetlist")
    public TableDataInfo getAlarmSetlist(PageDomain pageDomain, BizFeeAlarmSet set){
        IPage<BizFeeAlarmSet> page = baseService.selectAlarmSetList(pageDomain,set);
        return TableDataInfo.build(page.getRecords(),page.getTotal());
    }

    /**
     *查询预警设置详情
     * @param id
     * @return
     */
    @ApiOperation("查询预警设置详情")
    @GetMapping("/getAlarmSetInfo")
    public  R<BizFeeAlarmSet> getAlarmSetInfo(@NotEmpty(message = "主键不能为空") String id){
        return R.ok(baseService.getAlarmSetInfo(id));
    }

    /**
     * 新增
     * @param feeAlarmSet
     * @return
     */
    @ApiOperation("新增预警列表")
    @PostMapping("/add")
    public R<Void> addfeeAlarmSet(@Validated(add.class) @RequestBody BizFeeAlarmSet feeAlarmSet){
        boolean result = baseService.addfeeAlarmSet(feeAlarmSet);
        return result ? R.ok() : R.fail();
    }

    /**
     * 修改
     * @param feeAlarmSet
     * @return
     */
    @ApiOperation("编辑预警列表")
    @PostMapping("/edit")
    public R<Void> editfeeAlarmSet(@Validated(edit.class) @RequestBody  BizFeeAlarmSet feeAlarmSet){
        boolean result = baseService.editfeeAlarmSet(feeAlarmSet);
        return result ? R.ok() : R.fail();
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @ApiOperation("删除预警列表")
    @DeleteMapping("/remove/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] ids)
    {
        boolean result = baseService.delfeeAlarmSet(Arrays.asList(ids),true);
        return result ? R.ok() : R.fail();
    }
}
